package com.zx._07_数据库.demo;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

@Slf4j
public class 存储过程 {

    // 调用存储过程
    @Test
    public String test01(int id1, int id2, int money) {

        Connection conn = null;
        CallableStatement cs = null;
        String result = "";

        try {

            //获取连接
            conn = BaseDao.getConnection();

            //获得CallableStatement
            cs = conn.prepareCall("call zhuanzhang(?,?,?,?)");

            //对于in参数，赋值
            cs.setObject(1, id1);
            cs.setObject(2, id2);
            cs.setObject(3, money);

            //对于in参数，赋值
            cs.registerOutParameter(4, Types.VARCHAR);

            //执行 CallableStatement
            cs.execute();

            //获得出参
            result = cs.getString(4);

        } catch (Exception e) {
            log.debug("xxx");
            log.error("{}", e);

        } finally {
            BaseDao.release(conn, cs, null);
        }

        return result;
    }

}
